from django.views import View
# 导入返回响应
from SaaSDevelTool.data_return_response import create_response
# 导入错误信息装饰器
from SaaSDevelTool.data_return_response import error_message_detection
# 查询当前参数是否是int类型
from SaaSDevelTool.data_operation import is_number
# 获取数据库连接
from SaaSDevelTool.data_mysql_data import db
# 导入解析用户信息函数
from SaaSDevelTool.data_user_func import user
# 获取当前时间
from SaaSDevelTool.data_datetime_func import get_datatime
# 导入递归函数
from SaaSDevelUserLoginSettings.SaaSDevelUserLoginFunc import get_department_tree

"""
资源页面展示
"""


class SaaSDevelResourceQuery(View):
    @error_message_detection
    def get(self, request):
        # 进入数据库查询对应的数据
        query_base_info_resource_table_sql = """
            SELECT 
                resource.resource_id,
                resource.resource_name,
                resource.resource_urls,
                resource.resource_rid,
                resource.resource_level,
                biut.update_user,
                resource.resource_status,
                DATE_FORMAT(resource.update_time,'%Y-%m-%d %H:%i:%s') as update_time 
            FROM 
                db_center_rbac.base_info_resource_table resource 
            LEFT JOIN  
                db_center_rbac.base_info_user_table biut 
            ON 
                resource.update_user = biut.user_id 
            ;"""
        # 获取查询出来的数据
        query_base_info_resource_table_data = db.findAll(query_base_info_resource_table_sql)
        # 调用函数
        query_base_info_resource_table_tree_data = get_department_tree(query_base_info_resource_table_data)
        # 返回对应的数据
        return create_response(code=200, msg="", data=query_base_info_resource_table_tree_data)
